/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import algorithm.Data;
import algorithm.Sheduler;
import java.util.HashMap;
import java.util.Map;




import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;


import javax.servlet.http.HttpServletRequest;
import manager.ProfessorManager;
import manager.RoomManager;
import manager.SlotManager;
import manager.StudentManager;

import org.springframework.web.servlet.mvc.SimpleFormController;

public class ShedulerController extends SimpleFormController {

    private ProfessorManager professorManager;
    private RoomManager roomManager;
    private SlotManager slotManager;
    private StudentManager studentManager;

    public ShedulerController() {
        setCommandClass(Sheduler.class);
        setCommandName("sheduler");
    }

    @Override
    protected ModelAndView onSubmit(HttpServletRequest request,
            HttpServletResponse response, Object command, BindException errors)
            throws Exception {
        Sheduler sheduler = (Sheduler) command;
        Data data = new Data();
        data.readProfessorData(professorManager);
        data.readRoomData(roomManager);
        data.readSlotData(slotManager);
        data.readStudentData(studentManager);
        sheduler.generate(data);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("students", data.getStudents());
        map.put("sheduler", sheduler);
        return new ModelAndView("shedulerResult", "model", map);
    }

    public void setProfessorManager(ProfessorManager professorManager) {
        this.professorManager = professorManager;
    }

    public ProfessorManager getProfessorManager() {
        return professorManager;
    }

    public void setRoomManager(RoomManager roomManager) {
        this.roomManager = roomManager;
    }

    public RoomManager getRoomManager() {
        return roomManager;
    }

    public void setSlotManager(SlotManager slotManager) {
        this.slotManager = slotManager;
    }

    public SlotManager getSlotManager() {
        return slotManager;
    }

    public void setStudentManager(StudentManager studentManager) {
        this.studentManager = studentManager;
    }

    public StudentManager getStudentManager() {
        return studentManager;
    }
}
